Ext.define('Era.view.ManageScreen',{
   extend: 'Ext.grid.Panel',
   alias: 'widget.managescreen',
   store: null,
   
   border: false,
   frame: true,
   resizable: false,
   columns: [
        {
            header: 'Title',
            dataIndex: 'title',
            flex: 1,
            resizable: false,
            menuDisabled: true
        },
        {
            header: 'Start',
            dataIndex: 'start_date',
            flex: 1,
            resizable: false,
            menuDisabled: true,
            renderer: Ext.util.Format.dateRenderer('d-m-Y')
        },
        {
            xtype:'actioncolumn',  
            width:60,
            resizable: false,
            menuDisabled: true,
            items: [
                {
                    icon: 'data/images/apply.png',
                    tooltip: 'Finish',
                    stopSelection: true,

                    handler: function(grid, rowIndex, colIndex) {                       
                            
                        //get store
                        var store = Era.controller.Main.getStore('events');
                        
                        //get record
                        var record = store.getAt(rowIndex);
                        
                        //delete record
                        store.remove(record);
                        
                        
                        // add record to history
                        //Era.controller.Main.getStore('history').add(record);
                    }
                },
                {
                    icon: 'data/images/edit.gif',
                    tooltip: 'Edit',
                    stopSelection: true,

                    handler: function(grid, rowIndex, colIndex) {                       
                        
                        //get store
                        var store = Era.controller.Main.getStore('events');
                        
                        //get record
                        var record = store.getAt(rowIndex);

                        // create edit form
                        var screen = Ext.create('Era.view.EventScreen',{record: record});

                        // load form in the menu panel
                        Era.controller.Main.showMenuScreen(screen,true);
                        
                    }
                },
                {
                    icon: 'data/images/delete.gif',
                    tooltip: 'Delete',
                    stopSelection: true,

                    handler: function(grid, rowIndex, colIndex) {
                         
                        //get store
                        var store = Era.controller.Main.getStore('events');
                        
                        //get record
                        var record = store.getAt(rowIndex);
                        
                        //delete record
                        store.remove(record);
                        
                    }
                }
            ]
        }   
    ],
    
    viewConfig:{
        deferEmptyText: false,
        emptyText:'No events found.'
        
    },
    listeners: {
        itemmouseenter: function(view, record){
            Era.controller.Main.showPreviewWindow(view.up('window'),record);
        },
        itemmouseleave: function(){
            Era.controller.Main.hidePreviewWindow();
        }/*,
        itemclick: function(view,record){

            var screen = Ext.create('Era.view.FinishScreen',{record: record});
            
            // load form in the menu panel
            Era.controller.Main.showMenuScreen(screen,true);
        }*/
    }
});


